package com.aircjm.thinkinjava.part3;

/**
 * 将tank2的地址赋给tank1，tank1和tank2指向都是同一个对象，所以仅仅修改tank1,但是tank2的内容也跟着变化，因为他们是指向同一个对象。tank1的原有对象不再被引用，会被垃圾回收机制进行回收
 */
public class AssignmentTest {
    public static void main(String[] args) {
        Tank tank1 = new Tank();
        Tank tank2 = new Tank();

        tank1.level = 9;
        tank2.level = 10;
        System.out.println(tank1.level);
        System.out.println(tank2.level);
        System.out.println("------------");
        tank1 = tank2;
        System.out.println(tank1.level);
        System.out.println(tank2.level);
        System.out.println("------------");
        tank1.level = 27;
        System.out.println(tank1.level);
        System.out.println(tank2.level);
        System.out.println("------------");
    }
}

class Tank {
    int level;
}
